package at.jaki.ubb.crawling.demo.dataFinder;

import java.util.Collection;
import java.util.Collections;
import java.util.Date;

import org.apache.log4j.Logger;

import at.jaki.ubb.crawling.demo.dataTransformer.KeplerTransformer;
import at.jaki.ubb.crawling.model.DataFinderResult;
import at.jaki.ubb.crawling.model.RawData;
import at.jaki.ubb.crawling.model.Target;
import at.jaki.ubb.crawling.stlib.dataFinder.SimpleHttpClient;

public class KeplerWebfinder extends SimpleHttpClient {

	private static final Logger LOG = Logger.getLogger(KeplerWebfinder.class);

	// http://s3.amazonaws.com/ph-stars-production/APH52086771.json?_1339871259203=
	// APH52086771

	public static final String INPUT_TYPE = "keplerWebTarget";
	private static final String URL = "http://s3.amazonaws.com/ph-stars-production/%s.json?_1339871259203=";

	@Override
	public DataFinderResult<String, String> findData(Target<String> t) {

		LOG.info("getting star data: " + t.getValue());

		String uri = String.format(URL, t.getValue());
		String page = getPage(uri);

		RawData<String> rd = new RawData<String>(t.getValue(), page, new Date(), KeplerTransformer.INPUT_TYPE);

		return new DataFinderResult<String, String>(Collections.singletonList(rd), null);
	}

	@Override
	public Collection<String> getTypes() {
		return Collections.singletonList(INPUT_TYPE);
	}
}
